package Logic;

import java.util.Vector;
import System.DataManager;
import System.SystemLogger;

public class DataBase {
	
	private Vector<Movie> movies;
	private Vector<User> users;	
	private Vector<Rank> ranks;
	private DataManager dm = new DataManager();
	private SystemLogger systemLog;
	
	public DataBase(){
		systemLog = SystemLogger.getInstance();		
		systemLog.send("DataBase started");
		
		movies = dm.loadMoviesData();
		systemLog.send("movies data was loaded successfully");
		
		users = dm.loadUsersData();
		systemLog.send("users data was loaded successfully");
		
		ranks = dm.loadRanksData();
		systemLog.send("ranks data was loaded successfully");
	}

	
	public int getRating(User user,Movie movie){
		Vector<Rank> ranks = user.getRanks();
		int size = ranks.size();
		for (int i=0; i<size; i++){
			if (ranks.get(i).getMovie().equals(movie))
				return ranks.get(i).getRank();
		}
		return -1;
	}
	
	public void setRating(User user,Movie movie,Object rating){
		
	}
	
	public void removeRating(User user,Movie movie){
		
	}
	
	public void shutDown(){
		dm.saveData();
	}
	
	public int getUsersSize() {
		return users.size();
	}
	
	public User getUser(int i){
		return users.get(i);
	}
	
	public Vector<User> getUserVector (){
		return this.users;
	}
	
	public int getMoviesSize() {
		return movies.size();
	}
	
	public Movie getMovie(int i){
		return movies.get(i);
	}	
	
	public Vector<Movie> getMovieVector(){
		return movies;
	}
	
	public DataManager getDataManager(){
		return this.dm;
	}
}
